/**  
* @Title: ThreadTaskHelper.java
* @Package com.lemon.conf.content
* @Description: (一句话阐述):
* @author Ran_cc
* @date 2018年5月28日
* @version V1.0  
*/
package com.lemon.conf.content;

import com.google.common.collect.Maps;

import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Company: </p>
 * @author Ran_cc
 * @date 2018年5月28日
 * @版本 V 1.0 
 */
public class ThreadTaskHelper {

	private static ExecutorService executorService = Executors.newFixedThreadPool(20);

	private static Map RUNNING_REFRESH_CACHE = Maps.newConcurrentMap();

	public static Map<String, String> getRunningRefreshCache() {
		return RUNNING_REFRESH_CACHE;
	}

	public static void putRefreshCacheTask( String cacheKey ) {
		if (!hasRunningRefreshCacheTask(cacheKey)) {
			RUNNING_REFRESH_CACHE.put(cacheKey, cacheKey);
		}
	}

	public static void removeRefreshCacheTask( String cacheKey ) {
		if (hasRunningRefreshCacheTask(cacheKey)) {
			RUNNING_REFRESH_CACHE.remove(cacheKey);
		}
	}

	public static boolean hasRunningRefreshCacheTask( String cacheKey ) {
		return RUNNING_REFRESH_CACHE.containsKey(cacheKey);
	}

	public static void run( Runnable runnable ) {
		executorService.execute(runnable);
	}
}
